# Create your views here.
from core.ping import do_ping
from core.models import Host, PingResponse
from django.http import HttpResponse

def  request_ping(request, address):
    # Search for an actual host
    hosts = Host.objects.filter(address=address)
    if len(hosts) < 1:

    for host in hosts:
        pr = PingResponse()
        if do_ping(host):
            pr.response_time = 0
        pr.host = host
        pr.save()

    return HttpResponse(pr)
